package com.example.mobile2030606162zwh0506;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText edtTxtMainPassword;
    private Button btnMainLogin;
    private Button btnMainRegister;
    private Button btnMainCall;
    private Button btnMainIE;
    private Intent intent;
    private  String input;
    private Uri uri;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        edtTxtMainPassword = (EditText) findViewById(R.id.edtTxtMainPassword);
        btnMainLogin = (Button) findViewById(R.id.btnMainLogin);
        btnMainRegister = (Button) findViewById(R.id.btnMainRegister);
        btnMainCall = (Button) findViewById(R.id.btnMainCall);
        btnMainIE = (Button) findViewById(R.id.btnMainIE);
        btnMainLogin.setOnClickListener(this);
        btnMainRegister.setOnClickListener(this);
        btnMainCall.setOnClickListener(this);
        btnMainIE.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
            switch (v.getId()){
                case R.id.btnMainLogin://浏览器
                    input=edtTxtMainPassword.getText().toString().trim();
                    uri=Uri.parse(input);
                    intent=new Intent(Intent.ACTION_SENDTO,uri);
                    startActivity(intent);
                    break;
                case R.id.btnMainCall://相机
                    input= new String(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivity(intent);
                    break;
                case R.id.btnMainIE://地图
                    input=edtTxtMainPassword.getText().toString().trim();
                    uri=Uri.parse("geo:"+ input);
                    intent=new Intent(Intent.ACTION_VIEW,uri);
                    startActivity(intent);
                    break;
                case R.id.btnMainRegister://拨号码
                    input=edtTxtMainPassword.getText().toString().trim();
                    uri=Uri.parse("tel:"+ input);
                    intent=new Intent(Intent.ACTION_DIAL,uri);
                    startActivity(intent);
                    break;
            }
        }
    }
